﻿using Hotel.Application;
using Hotel.Application.Admins;
using Hotel.Application.DicTypes;
using Hotel.Application.DicTypes.Dto;
using Hotel.Domain;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace Hotel.Web.Controllers
{
    public class DicTypeController : BaseController<DicType, DicTypeCreateUpdateDto, DicTypeListDto>
    {
        private readonly IBaseService<DicType, DicTypeCreateUpdateDto, DicTypeListDto> service;
        private readonly IDicTypeService dicTypeService;

        public DicTypeController(
            IBaseService<DicType, DicTypeCreateUpdateDto, DicTypeListDto> service,
            IDicTypeService dicTypeService
            ) : base(service)
        {
            this.service = service;
            this.dicTypeService = dicTypeService;
        }

        [HttpGet]
        public async Task<IActionResult> ToPageListAsync(QueryDto dto, int PageSize = 10, int PageIndex = 1)
        {
            Expressionable<DicType> exp = new Expressionable<DicType>();
            exp.AndIF(!string.IsNullOrWhiteSpace(dto.Keywords), it => it.TypeName.Contains(dto.Keywords));
            exp.AndIF(dto.StartTime != null, it => it.CreateTime >= dto.StartTime);
            exp.AndIF(dto.EndTime != null, it => it.CreateTime <= dto.EndTime);
            var page = await base.PageAsync(exp, PageSize, PageIndex);
            return page;
        }

        [HttpGet]
        public async Task<IActionResult> CheckName(string TypeName, string TypeCode, long TypeId)
        {
            return Ok(await dicTypeService.CheckName(TypeName,TypeCode, TypeId));
        }
    }
}
